package com.three.redis;

import com.three.utils.JsonUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.junit.Before;
import org.junit.Test;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

/**
 * 参考:http://blog.csdn.net/mrxiagc/article/details/52799081
 * Created by mathua on 2017/5/30.
 */
public class RedisClusterTest {

    Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();

    JedisCluster cluster = null;

    @Before
    public void init() {
//        jedisClusterNodes.add(new HostAndPort("127.0.0.1", 7000));
//        jedisClusterNodes.add(new HostAndPort("127.0.0.1", 7001));
//        jedisClusterNodes.add(new HostAndPort("127.0.0.1", 7002));
//        jedisClusterNodes.add(new HostAndPort("127.0.0.1", 7003));
//        jedisClusterNodes.add(new HostAndPort("127.0.0.1", 7004));
//        jedisClusterNodes.add(new HostAndPort("127.0.0.1", 7005));
//        cluster = new JedisCluster(jedisClusterNodes, new GenericObjectPoolConfig());
    }

    @Test
    public void test() {

//        Player player = new Player("huang", 18, new Date());
//        cluster.set("huang", JsonUtils.toJson(player));
//        String ret = cluster.get("huang");
//        Player newPlayer = JsonUtils.fromJson(ret, Player.class);
//        System.out.println(ToStringBuilder.reflectionToString(newPlayer, ToStringStyle.JSON_STYLE));

    }

}